package servlets;

import hbt.dao.HibernateAlumnoDAO;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.Alumno;


public class ListarAlumnosServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		String opcion = req.getParameter("opcion");

		if(opcion.equalsIgnoreCase("volver")){
			RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/index.jsp");
			rd.forward(req, resp);
		}	
		else if(opcion.equalsIgnoreCase("display")){
			List<Alumno> alumnos = HibernateAlumnoDAO.getInstancia().getAlumnos();
			req.setAttribute("LISTAALUMNOS", alumnos);
			RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/listarAlumnos.jsp");
			rd.forward(req, resp);
		}
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		String opcion = req.getParameter("opcion");

		if(opcion.equalsIgnoreCase("volver")){
			RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/index.jsp");
			rd.forward(req, resp);
		}	
		else if(opcion.equalsIgnoreCase("display")){
			List<Alumno> alumnos = HibernateAlumnoDAO.getInstancia().getAlumnos();
			req.setAttribute("LISTAALUMNOS", alumnos);
			RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/listarAlumnos.jsp");
			rd.forward(req, resp);
		}
	}



}
